package com.example.service.impl;

import com.example.daoman.Notice;
import com.example.mapper.NoticeMapper;
import com.example.service.NoticeService;
import com.example.utils.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class NoticeServiceImpl implements NoticeService {


    @Autowired
    private NoticeMapper noticeMapper;


    //    管理员添加公告

    @Override
    public Message insertNotice(Notice notice) {
        Map<String,Object> map = new HashMap<>();
        map.put("uid",notice.getUid());
        map.put("title",notice.getTitle());
        map.put("content",notice.getContent());
        map.put("time",notice.getTime());
        boolean b = noticeMapper.insertNotice(map);
        return Message.out(200,"插入公告",b);
    }


    //    管理员删除公告

    @Override
    public Message removeNotice(Notice notice) {
        int nid = notice.getId();
        boolean b = noticeMapper.removeNoticeById(nid);
        return Message.out(200,"删除",b);
    }


//    用户查询所有已发布的公告

    @Override
    public Message getMyNotice() {
        List<Notice> myAllNotice = noticeMapper.getMyAllNotice();
        return Message.out(200,"查询成功",myAllNotice);
    }
}
